home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Apps / ArchiveUtils / nx_arc / arcdos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-20  |  4.9 KB  |  204 lines

  1. /*
  2.  * $Log:    arcdos.c,v $
  3.  * Revision 1.1  88/04/11  17:53:31  hyc
  4.  * Initial revision
  5.  * 
  6.  * Revision 1.2  87/12/19  04:20:26  hyc
  7.  * Replace reference to f->_file with fileno(f)
  8.  * 
  9.  * Revision 1.1  87/12/19  04:19:40  hyc
  10.  * Initial revision
  11.  * 
  12.  * Revision 1.4  87/08/13  17:03:16  hyc
  13.  * Run thru the indent program...
  14.  *  Revision 1.3  87/07/21  11:40:35  hyc *** empty
  15.  * log message ***
  16.  * 
  17.  * Revision 1.2  87/07/21  07:22:17  hyc added BSD goodies
  18.  * 
  19.  */
  20.  
  21. /*
  22.  * ARC - Archive utility - ARCDOS
  23.  * 
  24.  * Version 1.44, created on 07/25/86 at 14:17:38
  25.  * 
  26.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  27.  * 
  28.  * By:  Thom Henderson
  29.  * 
  30.  * Description: This file contains certain DOS level routines that assist in
  31.  * doing fancy things with an archive, primarily reading and setting the date
  32.  * and time last modified.
  33.  * 
  34.  * These are, by nature, system dependant functions.  But they are also, by
  35.  * nature, very expendable.
  36.  * 
  37.  * Language: Computer Innovations Optimizing C86
  38.  */
  39. #include <stdio.h>
  40. #include "arc.h"
  41. #ifdef MSDOS
  42. #include "fileio2.h"        /* needed for filehand */
  43. #endif
  44. #ifdef BSD
  45. #include <sys/types.h>
  46. #include <sys/stat.h>
  47. #include <sys/time.h>
  48. #include "tws.h"
  49. #endif
  50.  
  51. INT
  52. getstamp(f, date, time)        /* get a file's date/time stamp */
  53. #  ifndef MTS
  54.     FILE           *f;    /* file to get stamp from */
  55. #else
  56.     char           *f;    /* filename "" "" */
  57. #endif
  58.     unsigned INT   *date, *time;    /* storage for the stamp */
  59. {
  60. #ifdef MSDOS
  61.     struct {
  62.         int             ax, bx, cx, dx, si, di, ds, es;
  63.     }               reg;
  64.  
  65.     reg.ax = 0x5700;    /* get date/time */
  66.     reg.bx = filehand(f);    /* file handle */
  67.     if (sysint21(®, ®) & 1)    /* DOS call */
  68.         printf("Get timestamp fail (%d)\n", reg.ax);
  69.  
  70.     *date = reg.dx;        /* save date/time */
  71.     *time = reg.cx;
  72. #endif
  73. #ifdef BSD
  74.     struct stat    *buf;
  75.     int             day, hr, min, sec, yr, imon;
  76.     static char     mon[4], *mons[12] = {
  77.                    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  78.                     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  79.     };
  80.  
  81.     buf = (struct stat *) malloc(sizeof(struct stat));
  82.     fstat(fileno(f), buf);
  83.  
  84.     sscanf(ctime(&(buf->st_mtime)), "%*4s%3s%d%d:%d:%d%d", mon, &day, &hr, &min,
  85.            &sec, &yr);
  86.     for (imon = 0; imon < 12 && strcmp(mon, mons[imon]); imon++);
  87.  
  88.     *date = (unsigned INT) (((yr - 1980) << 9) + ((imon + 1) << 5) + day);
  89.     *time = (unsigned INT) ((hr << 11) + (min << 5) + sec / 2);
  90. #endif
  91. #ifdef MTS
  92.     fortran         timein(),
  93. #ifdef USEGFINFO
  94.                     gfinfo();
  95. #else
  96.                     fileinfo();
  97. #endif
  98.     int             stclk[2];
  99.     char            name[24];
  100.     struct bigtime {
  101.         int             greg;
  102.         int             year;
  103.         int             mon;
  104.         int             day;
  105.         int             hour;
  106.         int             min;
  107.         int             sec;
  108.         int             usec;
  109.         int             week;
  110.         int             toff;
  111.         int             tzn1;
  112.         int             tzn2;
  113.     }               tvec;
  114. #ifdef USEGFINFO
  115.     static int      gfflag = 0x0009, gfdummy[2] = {
  116.                                0, 0
  117.     };
  118.     int             gfcinfo[18];
  119. #else
  120.     static int      cattype = 2;
  121. #endif
  122.  
  123.     strcpy(name, f);
  124.     strcat(name, " ");
  125. #ifdef USEGFINFO
  126.     gfcinfo[0] = 18;
  127.     gfinfo(name, name, &gfflag, gfcinfo, gfdummy, gfdummy);
  128.     timein("*IBM MICROSECONDS*", &gfcinfo[16], &tvec);
  129. #else
  130.     fileinfo(name, &cattype, "CILCCT  ", stclk);
  131.     timein("*IBM MICROSECONDS*", stclk, &tvec);
  132. #endif
  133.  
  134.     *date = (unsigned INT) (((tvec.year - 1980) << 9) + ((tvec.mon) << 5) + tvec.day);
  135.     *time = (unsigned INT) ((tvec.hour << 11) + (tvec.min << 5) + tvec.sec / 2);
  136. #endif
  137. }
  138.  
  139. INT
  140. setstamp(f, date, time)        /* set a file's date/time stamp */
  141. #  ifdef  BSD
  142.     char           *f;    /* filename to stamp */
  143. #else
  144.     FILE           *f;    /* file to set stamp on */
  145. #endif
  146.     unsigned INT    date, time;    /* desired date, time */
  147. {
  148. #ifdef MSDOS
  149.     struct {
  150.         int             ax, bx, cx, dx, si, di, ds, es;
  151.     }               reg;
  152.  
  153.     fflush(f);        /* force any pending output */
  154.  
  155.     reg.ax = 0x5701;    /* set date/time */
  156.     reg.bx = filehand(f);    /* file handle */
  157.     reg.cx = time;        /* desired time */
  158.     reg.dx = date;        /* desired date */
  159.     if (sysint21(®, ®) & 1)    /* DOS call */
  160.         printf("Set timestamp fail (%d)\n", reg.ax);
  161. #endif
  162. #ifdef BSD
  163.     struct tws      tms;
  164.     struct timeval  tvp[2];
  165.     twscopy(&tms, dtwstime());
  166.     tms.tw_sec = (time & 31) * 2;
  167.     tms.tw_min = (time >> 5) & 63;
  168.     tms.tw_hour = (time >> 11);
  169.     tms.tw_mday = date & 31;
  170.     tms.tw_mon = ((date >> 5) & 15) - 1;
  171.     tms.tw_year = (date >> 9) + 80;
  172.     tms.tw_clock = 0L;
  173.     tvp[0].tv_sec = twclock(&tms);
  174.     tvp[1].tv_sec = tvp[0].tv_sec;
  175.     tvp[0].tv_usec = tvp[1].tv_usec = 0;
  176.     utimes(f, tvp);
  177. #endif
  178. }
  179.  
  180. INT
  181. filehand(stream)        /* find handle on a file */
  182.     struct bufstr  *stream;    /* file to grab onto */
  183. {
  184. #ifdef MSDOS
  185.     return stream->bufhand;    /* return DOS 2.0 file handle */
  186. #endif
  187. }
  188.  
  189. INT
  190. izadir(filename)        /* Is filename a directory? */
  191.     char           *filename;
  192. {
  193. #ifndef BSD
  194.     return (0);
  195. #else
  196.     struct stat     buf;
  197.  
  198.     if (stat(filename, &buf) != 0)
  199.         return (0);    /* Ignore if stat fails since */
  200.     else
  201.         return (buf.st_mode & S_IFDIR);    /* bad files trapped later */
  202. #endif
  203. }
  204.